package com.mxnet.chongjin.nci.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mxnet.chongjin.nci.R;
import com.mxnet.chongjin.nci.base.BaseActivity;
import com.mxnet.chongjin.nci.bean.Inspection;
import com.mxnet.chongjin.nci.view.ItemInspectionCheckView;

import java.util.List;

public class InspectionCheckActivity extends BaseActivity {
    private Context mContext;
    private Button mButtonBack, mButtonQuit;
    private LinearLayout mLinearLayout;
    private List<Inspection> mList;
    private TextView mTextViewLot, mTextViewSum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inspection_check);
        mContext = InspectionCheckActivity.this;

        mList = (List<Inspection>) getIntent().getSerializableExtra("inspectionData");

        mLinearLayout = findViewById(R.id.ll_inspection_check_list);

        mTextViewLot = findViewById(R.id.textview_inspection_check_lot);
        mTextViewLot.setText(getIntent().getStringExtra("lot"));

        mButtonBack = findViewById(R.id.btn_inspection_check_back);
        mButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mButtonQuit = findViewById(R.id.btn_inspection_check_quit);
        mButtonQuit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, IndexActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });

        int count = 0;
        for (Inspection inspection : mList) {
            ItemInspectionCheckView view = new ItemInspectionCheckView(mContext, R.layout.item_inspection_check);
            view.getTextView1().setText(inspection.getLot());
            view.getTextView2().setText(inspection.getLocationCode() + "");
            view.getTextView3().setText(TextUtils.isEmpty(inspection.getCheckQty() + "") ? "0" : inspection.getCheckQty() + "");
            view.getTextView4().setText(inspection.getInQty() + "");
            mLinearLayout.addView(view, 0);
            count += inspection.getInQty();
        }

        mTextViewSum = findViewById(R.id.textview_inspection_check_sum);
        mTextViewSum.setText(count + "");
    }
}
